package com.itmk.major.service.impl;

import com.itmk.major.dao.MajorDao;
import com.itmk.major.dao.impl.MajorDaoImpl;
import com.itmk.major.entity.Major;
import com.itmk.major.entity.MajorParm;
import com.itmk.major.entity.MajorResult;
import com.itmk.major.entity.MajorVo;
import com.itmk.major.service.MajorService;

import java.util.ArrayList;
import java.util.List;

public class MajorServiceImpl implements MajorService {
    private MajorDao majorDao = new MajorDaoImpl();
    @Override
    public void add(Major major) {
        majorDao.add(major);
    }

    @Override
    public Major getById(String majorId) {
        return majorDao.getById(majorId);
    }

    @Override
    public void updateById(Major major) {
        majorDao.updateById(major);
    }

    @Override
    public List<Major> list(MajorParm parm) {
        return majorDao.list(parm);
    }

    @Override
    public int getCount(MajorParm parm) {
        return majorDao.getCount(parm);
    }

    @Override
    public void delete(String majorId) {
        majorDao.delete(majorId);
    }

    @Override
    public List<Major> getMajorListBycollogeId(String collogeId) {
        return majorDao.getMajorListBycollogeId(collogeId);
    }

    @Override
    public List<Major> getAll() {
        return majorDao.getAll();
    }

    @Override
    public MajorResult majorCount() {
        List<MajorVo> majorVos = majorDao.majorCount();
        List<String> majorList = new ArrayList<>();
        List<Integer> countList = new ArrayList<>();
        if(majorVos != null && majorVos.size() > 0){
            for (int i=0;i<majorVos.size();i++){
                majorList.add(majorVos.get(i).getMajorName());
                countList.add(majorVos.get(i).getStuCount());
            }
        }
        MajorResult majorResult = new MajorResult();
        majorResult.setCountList(countList);
        majorResult.setMajorList(majorList);
        return majorResult;
    }

    @Override
    public int getTotal() {
        return majorDao.getTotal();
    }
}
